package com.yyx.app1.My_function.Controls.MyAppointment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.yyx.app1.Data.My.Appointment_Data;
import com.yyx.app1.My_function.UI.AppointmentInfo_Activity_;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/10/25.
 */
public class Item_Appointment_End_Adapter extends BaseAdapter {
    private List<Appointment_Data> data;
    private Context context;

    public Item_Appointment_End_Adapter(Context context) {
        this.context = context;
    }

    public void findAll()
    {
        data = new ArrayList<>();
        data.add(new Appointment_Data("75891275545","杭州第一宠物医院", Appointment_Data.Appointment_Data_Type.End,"2015.05.24 11:16","美容美发","王小琴","18888888888","小娃娃","2015/11/02 15:55","爱斯基摩犬","公"));
        data.add(new Appointment_Data("75891274444","杭州第一宠物医院",Appointment_Data.Appointment_Data_Type.End,"2015.01.26 18:16","医疗","陈大龙","18888888888","小娃娃","2015/11/02 15:55","爱斯基摩犬","公"));
        data.add(new Appointment_Data("75891273332","杭州第一宠物医院",Appointment_Data.Appointment_Data_Type.End,"2015.07.06 15:56","美发","董存瑞","18888888888","小娃娃","2015/11/02 15:55","爱斯基摩犬","公"));
        data.add(new Appointment_Data("75891275222","杭州第一宠物医院",Appointment_Data.Appointment_Data_Type.End,"2015.05.16 15:06","美容美发","陈大雷","18888888888","小娃娃","2015/11/02 15:55","爱斯基摩犬","公"));
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ItemView_Appointment it;
        if (convertView==null)
        {
            it = ItemView_Appointment_.build(context);
        }
        else
        {
            it = (ItemView_Appointment)convertView;
        }
        it.bind(data.get(position));
        it.setTag(data.get(position));
        it.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AppointmentInfo_Activity_.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("data", (Serializable) v.getTag());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        return it;
    }
}
